package com.hsmw.api.controller.driver;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsmw.api.mapper.HsmwItemMapper;
import com.hsmw.api.service.HsmwJobCollectionService;
import com.hsmw.common.base.BasePage;
import com.htn.common.core.base.DataResponse;
import com.htn.common.core.constant.CommonConstants;
import com.htn.common.core.utils.StringUtils;
import com.hsmw.domain.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.hsmw.common.base.BaseController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 作业信息收集  前端控制器
 * </p>
 *
 * @author tjy
 * @since 2021-07-30
 */
@RestController
@Api(tags = "作业信息收集")
@RequestMapping("/hsmw/job")
public class HsmwJobCollectionController extends BaseController<HsmwJobCollectionService, HsmwJobCollection> {



    @Autowired
    private HsmwJobCollectionService hsmwJobCollectionService;

    @Autowired
    private HsmwItemMapper hsmwItemMapper;


    @ApiOperation(value = "作业信息收集新增修改接口", notes = "作业信息收集新增修改接口", produces = "application/json")
    @PostMapping("jobConllectionSaveOrUpdate")
    public DataResponse jobConllectionSaveOrUpdate(@RequestBody HsmwJobCollection hsmwJobCollection){

        hsmwJobCollectionService.jobConllectionSaveOrUpdate(hsmwJobCollection);

        return new DataResponse(CommonConstants.ResponseStatus.SUCCESS);
    }


    @ApiOperation(value = "查询当前订单下的项目中的工长", notes = "查询当前订单下的项目中的工长", produces = "application/json")
    @PostMapping("findForManByOrderId")
    public DataResponse findForManByOrderId(String orderId){
        List list = new ArrayList<>();
        List<HsmwHtnUser> forManByOrderId = hsmwJobCollectionService.findForManByOrderId(orderId);
        for (HsmwHtnUser hsmwUser : forManByOrderId) {
            Map map = new HashMap();
            map.put("name",hsmwUser.getName());
            map.put("phone",hsmwUser.getUsername());
            list.add(map);
        }
        return new DataResponse(list);
    }


    @ApiOperation(value = "查询司机作业收集列表", notes = "作业信息收集新增修改接口", produces = "application/json")
    @PostMapping("findJobCollectionList")
    public DataResponse findJobCollectionList(@RequestBody @Valid BasePage<HsmwJobCollection> basePage){

        IPage page = new Page(basePage.getPageNo(), basePage.getPageSize());
        HsmwJobCollection hsmwJobCollection = basePage.getRequestData();
        IPage<HsmwJobCollection> data = hsmwJobCollectionService.findJobCollectionList(page, hsmwJobCollection);
        return new DataResponse(data);
    }



}

